package com.accompany.api.presenter;

import com.accompany.api.category.UnBindBlankCardCategory;
import com.accompany.base.BaseBean;
import com.accompany.utils.RetrofitUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class UnBindBlankCardPresenter implements UnBindBlankCardCategory.Presenter {
    private UnBindBlankCardCategory.View view;

    public UnBindBlankCardPresenter(UnBindBlankCardCategory.View view) {
        this.view = view;
    }

    @Override
    public void unBindCard(String mToken, String id) {
        RetrofitUtil.getInstance().getmService().unbind_blank_card(mToken,id).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                String result = null;
                try {
                    result = response.body().string();
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    BaseBean unbindInfo = gson.fromJson(result, BaseBean.class);
                    view.unBindCard(unbindInfo);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                view.OnShowErrorMsg(t.getMessage());
            }
        });
    }
}
